package com.dao;

import com.core.model.UploadImage;
import com.core.model.lxf.Good;
import com.core.model.lxf.GoodType;
import com.core.model.lxf.SecKillGoods;
import com.core.model.user.UserInfo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-7-22
 * Time: 下午11:20
 * To change this template use File | Settings | File Templates.
 */
public interface LxfDao extends EntityDao {

    List<Good> findAllStudent();

    void deleteObject(Object o);

    UploadImage findImageByGuid(String guid);

    UserInfo findUserInfoByUserGuid(String userInfoGuid);

    void addGood();

    GoodType findGoodTypeByGuid();

    List<Good> testHibernate();

    List<GoodType> testGoodType();

    /**
     * 根据key获取缓存来决定方法是否调用
     *
     * @param id
     * @return
     */
    @Cacheable(value = "good", key = "#root.args[0]")
    Good findGoodById(String id);

    /**
     * #result 只能用于@CachePut注解
     * 方法始终被调用
     *
     * @param good
     * @return
     */
    @CachePut(value = "good", key = "#result.id", condition = "#result.id>10")
    Good goodSave(Good good);

    /**
     * 清除缓存
     *
     * @param id
     */
    @CacheEvict(value = "good", key = "#p0", beforeInvocation = true, allEntries = true)
    void goodDeleteById(String id);

    int reduceStock(String id, Integer remainNum);

    void generateOrder(String consumer, String goodsId, Integer num);

    SecKillGoods findById(String id);
}
